package com.ecy.quadratic.utils;

import android.content.Context;
import android.os.Build;
import android.util.DisplayMetrics;
import android.view.Display;
import android.view.WindowManager;

import java.lang.reflect.Method;

/**
 * Created by Administrator on 2017/6/1.
 */
public class Utils {
    public static int getNavigationBarHeight(Context context) {
        Display display = ((WindowManager) context.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
        DisplayMetrics dm1 = new DisplayMetrics();
        display.getMetrics(dm1);

        DisplayMetrics dm2 = new DisplayMetrics();
        if (Build.VERSION.SDK_INT >= 17) {
            display.getRealMetrics(dm2);
        } else {
            try {
                Class c = Class.forName("android.view.Display");
                Method method = c.getMethod("getRealMetrics", DisplayMetrics.class);
                method.invoke(display, dm2);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }

        return dm2.heightPixels - dm1.heightPixels;
    }
}
